package com.vinny.springbootflowable2.mapper;

import com.vinny.springbootflowable2.model.entity.Expense;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ExpenseMapper {
    
    @Insert("INSERT INTO expense (process_instance_id, user_id, money, description, status) " +
            "VALUES (#{processInstanceId}, #{userId}, #{money}, #{description}, #{status})")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    void insert(Expense expense);
    
    @Update("UPDATE expense SET status = #{status} WHERE id = #{id}")
    void updateStatus(@Param("id") Long id, @Param("status") String status);
    
    @Select("SELECT * FROM expense WHERE user_id = #{userId}")
    List<Expense> findByUserId(@Param("userId") String userId);
    
    @Select("SELECT * FROM expense WHERE process_instance_id = #{processInstanceId}")
    Expense findByProcessInstanceId(@Param("processInstanceId") String processInstanceId);
    
    @Select("SELECT * FROM expense WHERE user_id = #{userId} AND status = #{status}")
    List<Expense> findByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
    
    @Select("SELECT COUNT(*) FROM expense WHERE user_id = #{userId} AND status = #{status}")
    long countByUserIdAndStatus(@Param("userId") String userId, @Param("status") String status);
    
    @Select("SELECT * FROM expense WHERE id = #{id}")
    Expense findById(@Param("id") Long id);
    
    @Delete("DELETE FROM expense WHERE id = #{id}")
    void deleteById(@Param("id") Long id);
} 